package com.jvtd.eyl.data.api;

import com.jvtd.bean.EmptyBean;
import com.jvtd.eyl.bean.binding.BookBean;
import com.jvtd.eyl.bean.binding.BrowseBean;
import com.jvtd.eyl.bean.binding.ClassBean;
import com.jvtd.eyl.bean.binding.PeriodicalBean;
import com.jvtd.eyl.bean.http.BannerBean;
import com.jvtd.eyl.bean.http.BaseResponse;
import com.jvtd.eyl.bean.http.LoginReqBean;
import com.jvtd.eyl.bean.http.LoginResBean;
import com.jvtd.eyl.bean.http.MyBookBean;
import com.jvtd.eyl.bean.http.TimeBean;
import com.jvtd.eyl.rxjava.JvtdRxSchedulers;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;
import retrofit2.Retrofit;

/**
 * Created by Administrator on 2017/10/16.
 * 网络
 */

public class AppApiHelper implements ApiHelper
{
  private final Retrofit mRetrofit;

  @Inject
  public AppApiHelper(Retrofit retrofit)
  {
    mRetrofit = retrofit;
  }

  @Override
  public Observable<LoginResBean> login(LoginReqBean loginReqBean) {
    return mRetrofit.create(ApiHelper.class)
            .login(loginReqBean)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<BannerBean>>> getBannerList() {
    return mRetrofit.create(ApiHelper.class)
            .getBannerList()
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<ClassBean>>> getClassList() {
    return mRetrofit.create(ApiHelper.class)
            .getClassList()
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<PeriodicalBean>>> getAllPeriodicalList() {
    return mRetrofit.create(ApiHelper.class)
            .getAllPeriodicalList()
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<ClassBean>>> getSecondaryClassList(String id) {
    return mRetrofit.create(ApiHelper.class)
            .getSecondaryClassList(id)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<PeriodicalBean>>> getClassPeriodicalList(String category_id) {
    return mRetrofit.create(ApiHelper.class)
            .getClassPeriodicalList(category_id)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<TimeBean>>> getTimeClassList(String document_id) {
    return mRetrofit.create(ApiHelper.class)
            .getTimeClassList(document_id)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<BookBean>>> getBookList(String document_id, String user_id, String sorts, String year) {
    return mRetrofit.create(ApiHelper.class)
            .getBookList(document_id,user_id,sorts,year)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<EmptyBean>> addBook(String user_id, String periodical_id) {
    return mRetrofit.create(ApiHelper.class)
            .addBook(user_id,periodical_id)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<EmptyBean>> delBook(String user_id, String periodical_id) {
    return mRetrofit.create(ApiHelper.class)
            .delBook(user_id,periodical_id)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<EmptyBean>> addBrowse(String user_id, String periodical_id) {
    return mRetrofit.create(ApiHelper.class)
            .addBrowse(user_id,periodical_id)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<BrowseBean>>> getMyBrowseList(String user_id) {
    return mRetrofit.create(ApiHelper.class)
            .getMyBrowseList(user_id)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<PeriodicalBean>>> searchPeriodicalList(String category_name) {
    return mRetrofit.create(ApiHelper.class)
            .searchPeriodicalList(category_name)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }

  @Override
  public Observable<BaseResponse<List<MyBookBean>>> getMyBookList(String user_id) {
    return mRetrofit.create(ApiHelper.class)
            .getMyBookList(user_id)
            .compose(JvtdRxSchedulers.applyObservableAsync());
  }
}
